import java.sql.*;
import java.util.*;

import oracle.sql.*;
//inserting into array type column using PreparedStatement.
class JdbcDemo28 {

	private static Scanner scan;

	public static void main(String[] args) throws Exception{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection cn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","kushwaha","oracle");
		PreparedStatement ps = cn.prepareStatement("insert into stud values(?,?)");
		scan = new Scanner(System.in);
		System.out.println("input name");
		String name = scan.next();
		ps.setString(1, name);
		System.out.println("input how many rows");
		int n = scan.nextInt();
		String c[] = new String[n];
		System.out.println("input courses name");
		for(int i=0; i<n; i++)
		c[i] = scan.next();
		
		ArrayDescriptor ad = ArrayDescriptor.createDescriptor("COURSETYPE", cn);
		ARRAY a = new ARRAY(ad, cn, c);
		ps.setArray(2, a);
		int count = ps.executeUpdate();
		System.out.println(count+   "rows inserted");
		ps.close();
		cn.close();
		
				
				// TODO Auto-generated method stub

	}

}
